package com.dhwl.hsh.driver.ui.dialog;

import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.dhwl.hsh.lib.utils.StringUtils;
import com.dhwl.hsh.lib.utils.ToastUtils;
import com.dhwl.hsh.driver.R;
import com.dhwl.hsh.driver.ui.activity.LoginActivity;

import org.w3c.dom.Text;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 添加小费对话框
 *
 * @author Derek.Kidd
 * @time 2016/5/3 9:29
 */
public class BillDialogFragment extends DialogFragment {

    @Bind(R.id.edit_bill)
    EditText editBill;

    @Bind(R.id.dialog_btn_cancel)
    Button dialogBtnCancel;
    @Bind(R.id.dialog_btn_sure)
    Button dialogBtnSure;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(android.support.v4.app.DialogFragment.STYLE_NORMAL, R.style.loading_dialog);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.dialog_bill_for_driver, container, false);
        ButterKnife.bind(this, v);
        getDialog().setCanceledOnTouchOutside(false);
        return v;

    }

    @OnClick(R.id.dialog_btn_sure)
    public void onSureClick(View view) {
        //小费校验
        String bill = editBill.getText().toString();
        if (TextUtils.isEmpty(bill)) {
            ToastUtils.show(getActivity(), "小费不能为空。", Toast.LENGTH_SHORT);
            return;
        }
        if (!StringUtils.isNumber(bill)) {
            ToastUtils.show(getActivity(), "请输入整数小费", Toast.LENGTH_SHORT);
            return;
        }
        ((BillInputListener)getActivity()).onSureClick(bill);
        dismissAllowingStateLoss();
    }

    @OnClick(R.id.dialog_btn_cancel)
    public void onCancelClick(View view)   {
      dismissAllowingStateLoss();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

   public interface BillInputListener {
        void onSureClick(String bill);
    }


}
